{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "afca994f-1b31-4c43-b369-5b2aa76407dc",
   "metadata": {
    "tags": [
     "remove-cell"
    ]
   },
   "outputs": [],
   "source": [
    "import os\n",
    "import sys\n",
    "from datetime import datetime\n",
    "from bokeh.models import ColumnDataSource, HoverTool\n",
    "from bokeh.plotting import figure, show\n",
    "sys.path.append(os.path.abspath('../../../scripts/'))\n",
    "import mdapi_functions as md\n",
    "from bokeh.io import output_notebook\n",
    "import bokeh.io as io\n",
    "from IPython.display import display, Markdown"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ef0c4646",
   "metadata": {},
   "source": [
    "# Temporal coverage of NHS England datasets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "7a325f63",
   "metadata": {
    "tags": [
     "remove-input"
    ]
   },
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "Last modified: 04 Jul 2025"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display(Markdown('Last modified: ' + datetime.now().strftime(\"%d %b %Y\")))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "500dbd8c",
   "metadata": {},
   "source": [
    "<div style=\"background-color: rgba(0, 178, 169, 0.3); padding: 5px; border-radius: 5px;\"><strong>The availability of NHS England datasets differs according to when each dataset was established, if the dataset has since been retired and the time periods permitted to flow to UK LLC.</strong></div>  \n",
    "<br> \n",
    "\n",
    "**Hover over the bar representing each dataset to see its full name and time range.**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "9b15e970",
   "metadata": {
    "tags": [
     "remove-input"
    ]
   },
   "outputs": [
    {
     "data": {
      "application/javascript": "'use strict';\n(function(root) {\n  function now() {\n    return new Date();\n  }\n\n  const force = true;\n\n  if (typeof root._bokeh_onload_callbacks === \"undefined\" || force === true) {\n    root._bokeh_onload_callbacks = [];\n    root._bokeh_is_loading = undefined;\n  }\n\nconst JS_MIME_TYPE = 'application/javascript';\n  const HTML_MIME_TYPE = 'text/html';\n  const EXEC_MIME_TYPE = 'application/vnd.bokehjs_exec.v0+json';\n  const CLASS_NAME = 'output_bokeh rendered_html';\n\n  /**\n   * Render data to the DOM node\n   */\n  function render(props, node) {\n    const script = document.createElement(\"script\");\n    node.appendChild(script);\n  }\n\n  /**\n   * Handle when an output is cleared or removed\n   */\n  function handleClearOutput(event, handle) {\n    function drop(id) {\n      const view = Bokeh.index.get_by_id(id)\n      if (view != null) {\n        view.model.document.clear()\n        Bokeh.index.delete(view)\n      }\n    }\n\n    const cell = handle.cell;\n\n    const id = cell.output_area._bokeh_element_id;\n    const server_id = cell.output_area._bokeh_server_id;\n\n    // Clean up Bokeh references\n    if (id != null) {\n      drop(id)\n    }\n\n    if (server_id !== undefined) {\n      // Clean up Bokeh references\n      const cmd_clean = \"from bokeh.io.state import curstate; print(curstate().uuid_to_server['\" + server_id + \"'].get_sessions()[0].document.roots[0]._id)\";\n      cell.notebook.kernel.execute(cmd_clean, {\n        iopub: {\n          output: function(msg) {\n            const id = msg.content.text.trim()\n            drop(id)\n          }\n        }\n      });\n      // Destroy server and session\n      const cmd_destroy = \"import bokeh.io.notebook as ion; ion.destroy_server('\" + server_id + \"')\";\n      cell.notebook.kernel.execute(cmd_destroy);\n    }\n  }\n\n  /**\n   * Handle when a new output is added\n   */\n  function handleAddOutput(event, handle) {\n    const output_area = handle.output_area;\n    const output = handle.output;\n\n    // limit handleAddOutput to display_data with EXEC_MIME_TYPE content only\n    if ((output.output_type != \"display_data\") || (!Object.prototype.hasOwnProperty.call(output.data, EXEC_MIME_TYPE))) {\n      return\n    }\n\n    const toinsert = output_area.element.find(\".\" + CLASS_NAME.split(' ')[0]);\n\n    if (output.metadata[EXEC_MIME_TYPE][\"id\"] !== undefined) {\n      toinsert[toinsert.length - 1].firstChild.textContent = output.data[JS_MIME_TYPE];\n      // store reference to embed id on output_area\n      output_area._bokeh_element_id = output.metadata[EXEC_MIME_TYPE][\"id\"];\n    }\n    if (output.metadata[EXEC_MIME_TYPE][\"server_id\"] !== undefined) {\n      const bk_div = document.createElement(\"div\");\n      bk_div.innerHTML = output.data[HTML_MIME_TYPE];\n      const script_attrs = bk_div.children[0].attributes;\n      for (let i = 0; i < script_attrs.length; i++) {\n        toinsert[toinsert.length - 1].firstChild.setAttribute(script_attrs[i].name, script_attrs[i].value);\n        toinsert[toinsert.length - 1].firstChild.textContent = bk_div.children[0].textContent\n      }\n      // store reference to server id on output_area\n      output_area._bokeh_server_id = output.metadata[EXEC_MIME_TYPE][\"server_id\"];\n    }\n  }\n\n  function register_renderer(events, OutputArea) {\n\n    function append_mime(data, metadata, element) {\n      // create a DOM node to render to\n      const toinsert = this.create_output_subarea(\n        metadata,\n        CLASS_NAME,\n        EXEC_MIME_TYPE\n      );\n      this.keyboard_manager.register_events(toinsert);\n      // Render to node\n      const props = {data: data, metadata: metadata[EXEC_MIME_TYPE]};\n      render(props, toinsert[toinsert.length - 1]);\n      element.append(toinsert);\n      return toinsert\n    }\n\n    /* Handle when an output is cleared or removed */\n    events.on('clear_output.CodeCell', handleClearOutput);\n    events.on('delete.Cell', handleClearOutput);\n\n    /* Handle when a new output is added */\n    events.on('output_added.OutputArea', handleAddOutput);\n\n    /**\n     * Register the mime type and append_mime function with output_area\n     */\n    OutputArea.prototype.register_mime_type(EXEC_MIME_TYPE, append_mime, {\n      /* Is output safe? */\n      safe: true,\n      /* Index of renderer in `output_area.display_order` */\n      index: 0\n    });\n  }\n\n  // register the mime type if in Jupyter Notebook environment and previously unregistered\n  if (root.Jupyter !== undefined) {\n    const events = require('base/js/events');\n    const OutputArea = require('notebook/js/outputarea').OutputArea;\n\n    if (OutputArea.prototype.mime_types().indexOf(EXEC_MIME_TYPE) == -1) {\n      register_renderer(events, OutputArea);\n    }\n  }\n  if (typeof (root._bokeh_timeout) === \"undefined\" || force === true) {\n    root._bokeh_timeout = Date.now() + 5000;\n    root._bokeh_failed_load = false;\n  }\n\n  const NB_LOAD_WARNING = {'data': {'text/html':\n     \"<div style='background-color: #fdd'>\\n\"+\n     \"<p>\\n\"+\n     \"BokehJS does not appear to have successfully loaded. If loading BokehJS from CDN, this \\n\"+\n     \"may be due to a slow or bad network connection. Possible fixes:\\n\"+\n     \"</p>\\n\"+\n     \"<ul>\\n\"+\n     \"<li>re-rerun `output_notebook()` to attempt to load from CDN again, or</li>\\n\"+\n     \"<li>use INLINE resources instead, as so:</li>\\n\"+\n     \"</ul>\\n\"+\n     \"<code>\\n\"+\n     \"from bokeh.resources import INLINE\\n\"+\n     \"output_notebook(resources=INLINE)\\n\"+\n     \"</code>\\n\"+\n     \"</div>\"}};\n\n  function display_loaded(error = null) {\n    const el = document.getElementById(null);\n    if (el != null) {\n      const html = (() => {\n        if (typeof root.Bokeh === \"undefined\") {\n          if (error == null) {\n            return \"BokehJS is loading ...\";\n          } else {\n            return \"BokehJS failed to load.\";\n          }\n        } else {\n          const prefix = `BokehJS ${root.Bokeh.version}`;\n          if (error == null) {\n            return `${prefix} successfully loaded.`;\n          } else {\n            return `${prefix} <b>encountered errors</b> while loading and may not function as expected.`;\n          }\n        }\n      })();\n      el.innerHTML = html;\n\n      if (error != null) {\n        const wrapper = document.createElement(\"div\");\n        wrapper.style.overflow = \"auto\";\n        wrapper.style.height = \"5em\";\n        wrapper.style.resize = \"vertical\";\n        const content = document.createElement(\"div\");\n        content.style.fontFamily = \"monospace\";\n        content.style.whiteSpace = \"pre-wrap\";\n        content.style.backgroundColor = \"rgb(255, 221, 221)\";\n        content.textContent = error.stack ?? error.toString();\n        wrapper.append(content);\n        el.append(wrapper);\n      }\n    } else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(() => display_loaded(error), 100);\n    }\n  }\n\n  function run_callbacks() {\n    try {\n      root._bokeh_onload_callbacks.forEach(function(callback) {\n        if (callback != null)\n          callback();\n      });\n    } finally {\n      delete root._bokeh_onload_callbacks\n    }\n    console.debug(\"Bokeh: all callbacks have finished\");\n  }\n\n  function load_libs(css_urls, js_urls, callback) {\n    if (css_urls == null) css_urls = [];\n    if (js_urls == null) js_urls = [];\n\n    root._bokeh_onload_callbacks.push(callback);\n    if (root._bokeh_is_loading > 0) {\n      console.debug(\"Bokeh: BokehJS is being loaded, scheduling callback at\", now());\n      return null;\n    }\n    if (js_urls == null || js_urls.length === 0) {\n      run_callbacks();\n      return null;\n    }\n    console.debug(\"Bokeh: BokehJS not loaded, scheduling load and callback at\", now());\n    root._bokeh_is_loading = css_urls.length + js_urls.length;\n\n    function on_load() {\n      root._bokeh_is_loading--;\n      if (root._bokeh_is_loading === 0) {\n        console.debug(\"Bokeh: all BokehJS libraries/stylesheets loaded\");\n        run_callbacks()\n      }\n    }\n\n    function on_error(url) {\n      console.error(\"failed to load \" + url);\n    }\n\n    for (let i = 0; i < css_urls.length; i++) {\n      const url = css_urls[i];\n      const element = document.createElement(\"link\");\n      element.onload = on_load;\n      element.onerror = on_error.bind(null, url);\n      element.rel = \"stylesheet\";\n      element.type = \"text/css\";\n      element.href = url;\n      console.debug(\"Bokeh: injecting link tag for BokehJS stylesheet: \", url);\n      document.body.appendChild(element);\n    }\n\n    for (let i = 0; i < js_urls.length; i++) {\n      const url = js_urls[i];\n      const element = document.createElement('script');\n      element.onload = on_load;\n      element.onerror = on_error.bind(null, url);\n      element.async = false;\n      element.src = url;\n      console.debug(\"Bokeh: injecting script tag for BokehJS library: \", url);\n      document.head.appendChild(element);\n    }\n  };\n\n  function inject_raw_css(css) {\n    const element = document.createElement(\"style\");\n    element.appendChild(document.createTextNode(css));\n    document.body.appendChild(element);\n  }\n\n  const js_urls = [\"https://cdn.bokeh.org/bokeh/release/bokeh-3.7.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-gl-3.7.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-widgets-3.7.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-tables-3.7.2.min.js\", \"https://cdn.bokeh.org/bokeh/release/bokeh-mathjax-3.7.2.min.js\"];\n  const css_urls = [];\n\n  const inline_js = [    function(Bokeh) {\n      Bokeh.set_log_level(\"info\");\n    },\nfunction(Bokeh) {\n    }\n  ];\n\n  function run_inline_js() {\n    if (root.Bokeh !== undefined || force === true) {\n      try {\n            for (let i = 0; i < inline_js.length; i++) {\n      inline_js[i].call(root, root.Bokeh);\n    }\n\n      } catch (error) {throw error;\n      }} else if (Date.now() < root._bokeh_timeout) {\n      setTimeout(run_inline_js, 100);\n    } else if (!root._bokeh_failed_load) {\n      console.log(\"Bokeh: BokehJS failed to load within specified timeout.\");\n      root._bokeh_failed_load = true;\n    } else if (force !== true) {\n      const cell = $(document.getElementById(null)).parents('.cell').data().cell;\n      cell.output_area.append_execute_result(NB_LOAD_WARNING)\n    }\n  }\n\n  if (root._bokeh_is_loading === 0) {\n    console.debug(\"Bokeh: BokehJS loaded, going straight to plotting\");\n    run_inline_js();\n  } else {\n    load_libs(css_urls, js_urls, function() {\n      console.debug(\"Bokeh: BokehJS plotting callback run at\", now());\n      run_inline_js();\n    });\n  }\n}(window));",
      "application/vnd.bokehjs_load.v0+json": ""
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "\n",
       "  <div id=\"ec532329-8eda-4f2f-bc50-5041cca7ec8f\" data-root-id=\"p1133\" style=\"display: contents;\"></div>\n"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": "(function(root) {\n  function embed_document(root) {\n  const docs_json = {\"c58a089e-9ac3-42df-a00e-248af64b12ae\":{\"version\":\"3.7.2\",\"title\":\"Bokeh Application\",\"roots\":[{\"type\":\"object\",\"name\":\"Figure\",\"id\":\"p1133\",\"attributes\":{\"height\":400,\"x_range\":{\"type\":\"object\",\"name\":\"DataRange1d\",\"id\":\"p1135\"},\"y_range\":{\"type\":\"object\",\"name\":\"FactorRange\",\"id\":\"p1143\",\"attributes\":{\"factors\":[\"CSDS\",\"IAPT\",\"MHSDS\",\"MORTALITY\",\"DEMOGRAPHICS\",\"CANCER\",\"CVAR\",\"CVS\",\"CHESS\",\"NPEX\",\"IELISA\",\"COVIDSGSS\",\"HESAE\",\"ECDS\",\"HESCC\",\"HESAPC_MAT\",\"HESAPC_ACP\",\"HESAPC\",\"HESOP\",\"PCM\",\"GDPPR\"]}},\"x_scale\":{\"type\":\"object\",\"name\":\"LinearScale\",\"id\":\"p1144\"},\"y_scale\":{\"type\":\"object\",\"name\":\"CategoricalScale\",\"id\":\"p1145\"},\"title\":{\"type\":\"object\",\"name\":\"Title\",\"id\":\"p1136\",\"attributes\":{\"text\":\"Temporal coverage of NHS England datasets in the UK LLC TRE\"}},\"outline_line_color\":null,\"renderers\":[{\"type\":\"object\",\"name\":\"GlyphRenderer\",\"id\":\"p1192\",\"attributes\":{\"data_source\":{\"type\":\"object\",\"name\":\"ColumnDataSource\",\"id\":\"p1183\",\"attributes\":{\"selected\":{\"type\":\"object\",\"name\":\"Selection\",\"id\":\"p1184\",\"attributes\":{\"indices\":[],\"line_indices\":[]}},\"selection_policy\":{\"type\":\"object\",\"name\":\"UnionRenderers\",\"id\":\"p1185\"},\"data\":{\"type\":\"map\",\"entries\":[[\"index\",{\"type\":\"ndarray\",\"array\":{\"type\":\"bytes\",\"data\":\"FAAAABMAAAASAAAAEQAAABAAAAAPAAAADgAAAA0AAAAMAAAACwAAAAoAAAAJAAAACAAAAAcAAAAGAAAABQAAAAQAAAADAAAAAgAAAAEAAAAAAAAA\"},\"shape\":[21],\"dtype\":\"int32\",\"order\":\"little\"}],[\"table\",{\"type\":\"ndarray\",\"array\":[\"CSDS\",\"IAPT\",\"MHSDS\",\"MORTALITY\",\"DEMOGRAPHICS\",\"CANCER\",\"CVAR\",\"CVS\",\"CHESS\",\"NPEX\",\"IELISA\",\"COVIDSGSS\",\"HESAE\",\"ECDS\",\"HESCC\",\"HESAPC_MAT\",\"HESAPC_ACP\",\"HESAPC\",\"HESOP\",\"PCM\",\"GDPPR\"],\"shape\":[21],\"dtype\":\"object\",\"order\":\"little\"}],[\"collection_start\",{\"type\":\"ndarray\",\"array\":{\"type\":\"bytes\",\"data\":\"AACAcCTHdEIAAEA4s2ZzQgAAQPwrpXBCAACAI/ofZUIAAAArsJtvQgAAALDEXh1CAADAlLlhd0IAAMCUuWF3QgAAgEc2CXdCAADAmTATd0IAAIBpb0R3QgAAwJkwE3dCAAAAD6cacUIAAAC4U+11QgAAgId0kHFCAAAATO7Ha0IAAAAQZwZpQgAAgDVd8WlCAACAvNCIbkIAAADB/o1rwgAAAMH+jWvC\"},\"shape\":[21],\"dtype\":\"float64\",\"order\":\"little\"}],[\"collection_end\",{\"type\":\"ndarray\",\"array\":{\"type\":\"bytes\",\"data\":\"AADAuSt9eUIAAMC5K315QgAAwLkrfXlCAADAuSt9eUIAAMC5K315QgAAwLkrfXlCAADAuSt9eUIAAMC5K315QgAAgHsNOXhCAADAuSt9eUIAAMC5K315QgAAwLkrfXlCAADAlLlhd0IAAMC5K315QgAAwLkrfXlCAADAuSt9eUIAAED3tPNwQgAAwLkrfXlCAADAuSt9eUIAAMC5K315QgAAwLkrfXlC\"},\"shape\":[21],\"dtype\":\"float64\",\"order\":\"little\"}],[\"table_name\",{\"type\":\"ndarray\",\"array\":[\"Community Services Data Set (CSDS)\",\"Talking Therapies for Anxiety and Depression (IAPT)\",\"Mental Health Services Data Set\",\"Civil Registration of Deaths Dataset\",\"Demographics Dataset\",\"Cancer Registration Dataset\",\"COVID-19 Vaccination Adverse Reactions\",\"COVID-19 Vaccination Status\",\"COVID-19 Hospitalisation in England Surveillance System (CHESS)\",\"National Pathology Exchange\",\"Enzyme-Linked Immunosorbent Assay\",\"COVID-19 Second Generation Surveillance System (SGSS)\",\"Hospital Episode Statistics (HES) Accident and Emergency Dataset\",\"Emergency Care Data Set (ECDS)\",\"Hospital Episode Statistics (HES) Critical Care (CC) Minimum Dataset\",\"Hospital Episode Statistics (HES) Maternity Dataset\",\"Hospital Episode Statistics (HES) Augmented Care Periods (ACP) Dataset\",\"Hospital Episode Statistics (HES) Admitted Patient Care (APC) Dataset\",\"Hospital Episode Statistics (HES) Outpatients Dataset\",\"Primary Care Medicines (PCM)\",\"General Practice Extraction Service (GPES) Data for Pandemic Planning and Research\"],\"shape\":[21],\"dtype\":\"object\",\"order\":\"little\"}]]}}},\"view\":{\"type\":\"object\",\"name\":\"CDSView\",\"id\":\"p1193\",\"attributes\":{\"filter\":{\"type\":\"object\",\"name\":\"AllIndices\",\"id\":\"p1194\"}}},\"glyph\":{\"type\":\"object\",\"name\":\"HBar\",\"id\":\"p1189\",\"attributes\":{\"y\":{\"type\":\"field\",\"field\":\"table\"},\"height\":{\"type\":\"value\",\"value\":0.4},\"left\":{\"type\":\"field\",\"field\":\"collection_start\"},\"right\":{\"type\":\"field\",\"field\":\"collection_end\"},\"line_color\":{\"type\":\"value\",\"value\":\"#1f77b4\"},\"fill_color\":{\"type\":\"value\",\"value\":\"#00b289\"}}},\"nonselection_glyph\":{\"type\":\"object\",\"name\":\"HBar\",\"id\":\"p1190\",\"attributes\":{\"y\":{\"type\":\"field\",\"field\":\"table\"},\"height\":{\"type\":\"value\",\"value\":0.4},\"left\":{\"type\":\"field\",\"field\":\"collection_start\"},\"right\":{\"type\":\"field\",\"field\":\"collection_end\"},\"line_color\":{\"type\":\"value\",\"value\":\"#1f77b4\"},\"line_alpha\":{\"type\":\"value\",\"value\":0.1},\"fill_color\":{\"type\":\"value\",\"value\":\"#00b289\"},\"fill_alpha\":{\"type\":\"value\",\"value\":0.1},\"hatch_alpha\":{\"type\":\"value\",\"value\":0.1}}},\"muted_glyph\":{\"type\":\"object\",\"name\":\"HBar\",\"id\":\"p1191\",\"attributes\":{\"y\":{\"type\":\"field\",\"field\":\"table\"},\"height\":{\"type\":\"value\",\"value\":0.4},\"left\":{\"type\":\"field\",\"field\":\"collection_start\"},\"right\":{\"type\":\"field\",\"field\":\"collection_end\"},\"line_color\":{\"type\":\"value\",\"value\":\"#1f77b4\"},\"line_alpha\":{\"type\":\"value\",\"value\":0.2},\"fill_color\":{\"type\":\"value\",\"value\":\"#00b289\"},\"fill_alpha\":{\"type\":\"value\",\"value\":0.2},\"hatch_alpha\":{\"type\":\"value\",\"value\":0.2}}}}}],\"toolbar\":{\"type\":\"object\",\"name\":\"Toolbar\",\"id\":\"p1142\",\"attributes\":{\"tools\":[{\"type\":\"object\",\"name\":\"PanTool\",\"id\":\"p1170\"},{\"type\":\"object\",\"name\":\"WheelZoomTool\",\"id\":\"p1171\",\"attributes\":{\"renderers\":\"auto\"}},{\"type\":\"object\",\"name\":\"BoxZoomTool\",\"id\":\"p1172\",\"attributes\":{\"dimensions\":\"both\",\"overlay\":{\"type\":\"object\",\"name\":\"BoxAnnotation\",\"id\":\"p1173\",\"attributes\":{\"syncable\":false,\"line_color\":\"black\",\"line_alpha\":1.0,\"line_width\":2,\"line_dash\":[4,4],\"fill_color\":\"lightgrey\",\"fill_alpha\":0.5,\"level\":\"overlay\",\"visible\":false,\"left\":{\"type\":\"number\",\"value\":\"nan\"},\"right\":{\"type\":\"number\",\"value\":\"nan\"},\"top\":{\"type\":\"number\",\"value\":\"nan\"},\"bottom\":{\"type\":\"number\",\"value\":\"nan\"},\"left_units\":\"canvas\",\"right_units\":\"canvas\",\"top_units\":\"canvas\",\"bottom_units\":\"canvas\",\"handles\":{\"type\":\"object\",\"name\":\"BoxInteractionHandles\",\"id\":\"p1179\",\"attributes\":{\"all\":{\"type\":\"object\",\"name\":\"AreaVisuals\",\"id\":\"p1178\",\"attributes\":{\"fill_color\":\"white\",\"hover_fill_color\":\"lightgray\"}}}}}}}},{\"type\":\"object\",\"name\":\"SaveTool\",\"id\":\"p1180\"},{\"type\":\"object\",\"name\":\"ResetTool\",\"id\":\"p1181\"},{\"type\":\"object\",\"name\":\"HelpTool\",\"id\":\"p1182\"},{\"type\":\"object\",\"name\":\"HoverTool\",\"id\":\"p1195\",\"attributes\":{\"renderers\":\"auto\",\"tooltips\":[[\"Name\",\"@table_name\"],[\"Start\",\"@collection_start{%b-%Y}\"],[\"End\",\"@collection_end{%b-%Y}\"]],\"formatters\":{\"type\":\"map\",\"entries\":[[\"@collection_start\",\"datetime\"],[\"@collection_end\",\"datetime\"]]}}}]}},\"toolbar_location\":null,\"left\":[{\"type\":\"object\",\"name\":\"CategoricalAxis\",\"id\":\"p1165\",\"attributes\":{\"ticker\":{\"type\":\"object\",\"name\":\"CategoricalTicker\",\"id\":\"p1166\"},\"formatter\":{\"type\":\"object\",\"name\":\"CategoricalTickFormatter\",\"id\":\"p1167\"},\"major_label_policy\":{\"type\":\"object\",\"name\":\"AllLabels\",\"id\":\"p1168\"}}}],\"below\":[{\"type\":\"object\",\"name\":\"DatetimeAxis\",\"id\":\"p1146\",\"attributes\":{\"ticker\":{\"type\":\"object\",\"name\":\"DatetimeTicker\",\"id\":\"p1147\",\"attributes\":{\"num_minor_ticks\":5,\"tickers\":[{\"type\":\"object\",\"name\":\"AdaptiveTicker\",\"id\":\"p1148\",\"attributes\":{\"num_minor_ticks\":0,\"mantissas\":[1,2,5],\"max_interval\":500.0}},{\"type\":\"object\",\"name\":\"AdaptiveTicker\",\"id\":\"p1149\",\"attributes\":{\"num_minor_ticks\":0,\"base\":60,\"mantissas\":[1,2,5,10,15,20,30],\"min_interval\":1000.0,\"max_interval\":1800000.0}},{\"type\":\"object\",\"name\":\"AdaptiveTicker\",\"id\":\"p1150\",\"attributes\":{\"num_minor_ticks\":0,\"base\":24,\"mantissas\":[1,2,4,6,8,12],\"min_interval\":3600000.0,\"max_interval\":43200000.0}},{\"type\":\"object\",\"name\":\"DaysTicker\",\"id\":\"p1151\",\"attributes\":{\"days\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31]}},{\"type\":\"object\",\"name\":\"DaysTicker\",\"id\":\"p1152\",\"attributes\":{\"days\":[1,4,7,10,13,16,19,22,25,28]}},{\"type\":\"object\",\"name\":\"DaysTicker\",\"id\":\"p1153\",\"attributes\":{\"days\":[1,8,15,22]}},{\"type\":\"object\",\"name\":\"DaysTicker\",\"id\":\"p1154\",\"attributes\":{\"days\":[1,15]}},{\"type\":\"object\",\"name\":\"MonthsTicker\",\"id\":\"p1155\",\"attributes\":{\"months\":[0,1,2,3,4,5,6,7,8,9,10,11]}},{\"type\":\"object\",\"name\":\"MonthsTicker\",\"id\":\"p1156\",\"attributes\":{\"months\":[0,2,4,6,8,10]}},{\"type\":\"object\",\"name\":\"MonthsTicker\",\"id\":\"p1157\",\"attributes\":{\"months\":[0,4,8]}},{\"type\":\"object\",\"name\":\"MonthsTicker\",\"id\":\"p1158\",\"attributes\":{\"months\":[0,6]}},{\"type\":\"object\",\"name\":\"YearsTicker\",\"id\":\"p1159\"}]}},\"formatter\":{\"type\":\"object\",\"name\":\"DatetimeTickFormatter\",\"id\":\"p1162\",\"attributes\":{\"seconds\":\"%T\",\"minsec\":\"%T\",\"minutes\":\"%H:%M\",\"hours\":\"%H:%M\",\"days\":\"%b %d\",\"months\":\"%b %Y\",\"strip_leading_zeros\":[\"microseconds\",\"milliseconds\",\"seconds\"],\"boundary_scaling\":false,\"context\":{\"type\":\"object\",\"name\":\"DatetimeTickFormatter\",\"id\":\"p1161\",\"attributes\":{\"microseconds\":\"%T\",\"milliseconds\":\"%T\",\"seconds\":\"%b %d, %Y\",\"minsec\":\"%b %d, %Y\",\"minutes\":\"%b %d, %Y\",\"hourmin\":\"%b %d, %Y\",\"hours\":\"%b %d, %Y\",\"days\":\"%Y\",\"months\":\"\",\"years\":\"\",\"boundary_scaling\":false,\"hide_repeats\":true,\"context\":{\"type\":\"object\",\"name\":\"DatetimeTickFormatter\",\"id\":\"p1160\",\"attributes\":{\"microseconds\":\"%b %d, %Y\",\"milliseconds\":\"%b %d, %Y\",\"seconds\":\"\",\"minsec\":\"\",\"minutes\":\"\",\"hourmin\":\"\",\"hours\":\"\",\"days\":\"\",\"months\":\"\",\"years\":\"\",\"boundary_scaling\":false,\"hide_repeats\":true}},\"context_which\":\"all\"}},\"context_which\":\"all\"}},\"axis_label\":\"Dataset Collection Period\",\"major_label_policy\":{\"type\":\"object\",\"name\":\"AllLabels\",\"id\":\"p1163\"}}}],\"center\":[{\"type\":\"object\",\"name\":\"Grid\",\"id\":\"p1164\",\"attributes\":{\"axis\":{\"id\":\"p1146\"}}},{\"type\":\"object\",\"name\":\"Grid\",\"id\":\"p1169\",\"attributes\":{\"dimension\":1,\"axis\":{\"id\":\"p1165\"},\"grid_line_color\":null}}]}}]}};\n  const render_items = [{\"docid\":\"c58a089e-9ac3-42df-a00e-248af64b12ae\",\"roots\":{\"p1133\":\"ec532329-8eda-4f2f-bc50-5041cca7ec8f\"},\"root_ids\":[\"p1133\"]}];\n  void root.Bokeh.embed.embed_items_notebook(docs_json, render_items);\n  }\n  if (root.Bokeh !== undefined) {\n    embed_document(root);\n  } else {\n    let attempts = 0;\n    const timer = setInterval(function(root) {\n      if (root.Bokeh !== undefined) {\n        clearInterval(timer);\n        embed_document(root);\n      } else {\n        attempts++;\n        if (attempts > 100) {\n          clearInterval(timer);\n          console.log(\"Bokeh: ERROR: Unable to run BokehJS code because BokehJS library is missing\");\n        }\n      }\n    }, 10, root)\n  }\n})(window);",
      "application/vnd.bokehjs_exec.v0+json": ""
     },
     "metadata": {
      "application/vnd.bokehjs_exec.v0+json": {
       "id": "p1133"
      }
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "output_notebook(hide_banner=True)\n",
    "dss1 = md.get_md_api_dss()\n",
    "dss1 = dss1[dss1[\"source\"] == \"NHSE\"][[\"table\", \"collection_start\", \"collection_end\", \"table_name\"]]\n",
    "dss1 = dss1[~dss1[\"collection_start\"].isnull()]\n",
    "dss1 = dss1.set_index(keys=\"table\", drop=False).reindex(\n",
    "    [\n",
    "        \"GDPPR\",\n",
    "        \"PCM\",\n",
    "        \"HESOP\",\n",
    "        \"HESAPC\",\n",
    "        \"HESAPC_ACP\",\n",
    "        \"HESAPC_MAT\",\n",
    "        \"HESCC\",\n",
    "        \"ECDS\",\n",
    "        \"HESAE\",\n",
    "        \"COVIDSGSS\",\n",
    "        \"IELISA\",\n",
    "        \"NPEX\",\n",
    "        \"CHESS\",\n",
    "        \"CVS\",\n",
    "        \"CVAR\",\n",
    "        \"CANCER\",\n",
    "        \"DEMOGRAPHICS\",\n",
    "        \"MORTALITY\",\n",
    "        \"MHSDS\",\n",
    "        \"IAPT\",\n",
    "        \"CSDS\"\n",
    "]).reset_index(drop=True).iloc[::-1]\n",
    "\n",
    "\n",
    "def ins_ongoing_date(x):\n",
    "    if x == \"ongoing\":\n",
    "        return datetime.now().date()\n",
    "    else:\n",
    "        return datetime.strptime(x, '%m/%Y').date()\n",
    "dss1[\"collection_end\"] = dss1[\"collection_end\"].apply(lambda x: ins_ongoing_date(x))\n",
    "dss1[\"collection_start\"] = dss1[\"collection_start\"].apply(lambda x: ins_ongoing_date(x))\n",
    "dss1.loc[0, \"collection_start\"] = datetime.strptime(\"01/1940\", '%m/%Y').date()\n",
    "\n",
    "p = figure(x_axis_type=\"datetime\", y_range=dss1[\"table\"].to_list(), width=600, height=400, toolbar_location=None,\n",
    "           title=\"Temporal coverage of NHS England datasets in the UK LLC TRE\")\n",
    "p.hbar(y=\"table\", left='collection_start', right='collection_end', height=0.4, source=ColumnDataSource(dss1), fill_color=\"#00b289\")\n",
    "\n",
    "hover = HoverTool(tooltips = [(\"Name\",\"@table_name\"), (\"Start\",\"@collection_start{%b-%Y}\"),(\"End\", \"@collection_end{%b-%Y}\")], formatters={\"@collection_start\":\"datetime\", \"@collection_end\":\"datetime\"})\n",
    "p.add_tools(hover)\n",
    "\n",
    "p.ygrid.grid_line_color = None\n",
    "p.xaxis.axis_label = \"Dataset Collection Period\"\n",
    "\n",
    "p.outline_line_color = None\n",
    "show(p)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "jupbook",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}